import matplotlib.pyplot as plt
import plotly
import seaborn as sns
import plotly.express as px
plotly.offline.init_notebook_mode()
This is the most classic chart provided by Matplotlib. I used some value to write my name on it.
fig, ax = plt.subplots() # Create a figure containing a single axes.
# ax.plot([1, 1, 1, 2, 1, 2], [1, 3, 2, 3, 2, 1]) # K
# ax.plot([3, 2.5, 2.5, 2.5, 3, 3.5, 3.5], [1, 1.75, 3, 1.75, 1, 1.75, 3]) # U
# ax.plot([5.5, 4.5, 4.5, 5.5, 5.5, 4.5], [3, 3, 2, 2, 1, 1]) # S
# ax.plot([6, 6, 6, 7, 7, 7], [3, 1, 2, 2, 3, 1]) # H
# ax.plot([7.5, 8.5, 8, 8, 7.5, 8.5], [3, 3, 3, 1, 1, 1]) # I
# ax.plot([9, 9, 9, 10, 10, 10], [3, 1, 2, 2, 3, 1]) # H
# ax.plot([12.5, 11.5, 11.5, 12.5], [3, 3, 1, 1]) # C
# ax.plot([13, 13, 13, 14, 14, 14], [3, 1, 2, 2, 3, 1]) # H
# ax.plot([14.5, 15.5, 15, 15, 14.5, 15.5], [3, 3, 3, 1, 1, 1]) # I
# ax.plot([17, 16, 16, 17, 16, 16, 17], [3, 3, 2, 2, 2, 1, 1]) # E
# ax.plot([17.5, 17.5, 17.5, 18.5, 18.5, 18.5], [3, 1, 2, 2, 3, 1]) # H
ax.plot([1, 1, 1, 2, 1, 2], [1, 5, 3, 5, 3, 1]) # K
ax.plot([3, 2.5, 2.5, 2.5, 3, 3.5, 3.5], [1, 3, 5, 3, 1, 3, 5]) # U
ax.plot([5.5, 4.5, 4.5, 5.5, 5.5, 4.5], [5, 5, 3, 3, 1, 1]) # S
ax.plot([6, 6, 6, 7, 7, 7], [5, 1, 3, 3, 5, 1]) # H
ax.plot([7.5, 8.5, 8, 8, 7.5, 8.5], [5, 5, 5, 1, 1, 1]) # I
ax.plot([9, 9, 9, 10, 10, 10], [5, 1, 3, 3, 5, 1]) # H
ax.plot([12.5, 11.5, 11.5, 12.5], [5,5,1,1]) # C
ax.plot([13, 13, 13, 14, 14, 14], [5, 1, 3, 3, 5, 1]) # H
ax.plot([14.5, 15.5, 15, 15, 14.5, 15.5], [5, 5, 5, 1, 1, 1]) # I
ax.plot([17, 16, 16, 17, 16, 16, 17], [5, 5,3,3,3,1,1]) # E
ax.plot([17.5, 17.5, 17.5, 18.5, 18.5, 18.5], [5, 1, 3, 3, 5, 1]) # H
[<matplotlib.lines.Line2D at 0x2294776a790>]
Unlike a typical bar chart, this graph allows the addition of numerical values for each different category
species = ("Adelie", "Chinstrap", "Gentoo")
penguin_means = {
'Bill Depth': (18.35, 18.43, 14.98),
'Bill Length': (38.79, 48.83, 47.50),
'Flipper Length': (189.95, 195.82, 217.19),
}
x = np.arange(len(species)) # the label locations
width = 0.25 # the width of the bars
multiplier = 0
fig, ax = plt.subplots(layout='constrained')
for attribute, measurement in penguin_means.items():
offset = width * multiplier
rects = ax.bar(x + offset, measurement, width, label=attribute)
ax.bar_label(rects, padding=3)
multiplier += 1
# Add some text for labels, title and custom x-axis tick labels, etc.
ax.set_ylabel('Length (mm)')
ax.set_title('Penguin attributes by species')
ax.set_xticks(x + width, species)
ax.legend(loc='upper left', ncols=3)
ax.set_ylim(0, 250)
plt.show()
c:\Users\USER\Desktop\Foundatuin_ML\projects\CSCN8010\venv\CSCN8010_classic_ml\Lib\site-packages\IPython\core\pylabtools.py:152: UserWarning: constrained_layout not applied because axes sizes collapsed to zero. Try making figure larger or axes decorations smaller.
About the first expression of this chart for me is that just the harmonious color display, but look at it in detail, found that this chart can use on Regression, Linear dataset.
sns.set_theme()
# Load the penguins dataset
penguins = sns.load_dataset("penguins")
# Plot sepal width as a function of sepal_length across days
g = sns.lmplot(
data=penguins,
x="bill_length_mm", y="bill_depth_mm", hue="species",
height=5
)
# Use more informative axis labels than are provided by default
g.set_axis_labels("Snoot length (mm)", "Snoot depth (mm)")
<seaborn.axisgrid.FacetGrid at 0x22967dcbbd0>
This is another example from Seaborn. It can depict the differences in distribution and numerical values On the graph.
sns.set_theme(style="ticks")
# Load the penguins dataset
penguins = sns.load_dataset("penguins")
# Show the joint distribution using kernel density estimation
g = sns.jointplot(
data=penguins,
x="bill_length_mm", y="bill_depth_mm", hue="species",
kind="kde",
)
I rarely see the chart which can be a triangle. It use the feature of triangle to display and define the relationship two provided values.
df = px.data.election()
fig = px.scatter_ternary(
df,
a="Joly",
b="Coderre",
c="Bergeron",
hover_name="district",
color="winner",
size="total",
size_max=15,
color_discrete_map={"Joly": "orange", "Bergeron": "green", "Coderre": "red"},
)
fig.show()
Here is my notebook github address link: CSCN8010-labs.
Here is my HTML for python visualization: matplotlib_tutorial.
| Matplotlib | Seaborn | Plotly |
|---|---|---|
| 2 Examples | 2 Examples | 1 Example |
| table ex | table ex | table ex |
